package sort.recharge;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

public final class RechargeListUtil
{

    public static List<PaymentRechargeList> getCandidatedRechargeList(final List<PaymentRechargeList> rechargeLists, final String supportFreeVirtualCurrency) {
        final List<PaymentRechargeList> candidatedRechargeList = new ArrayList<PaymentRechargeList>();
        for (final PaymentRechargeList recharge : rechargeLists) {
            final CurrencyType currencyType = recharge.getVirtualCurrencyType();
            System.out.println(currencyType);
            if (!CurrencyType.INVALID.equals((Object)currencyType)) {
                if ("0".equals(supportFreeVirtualCurrency) && CurrencyType.FREE.equals((Object)currencyType)) {
                    continue;
                }
                candidatedRechargeList.add(recharge);
            }
        }
        Collections.<PaymentRechargeList>sort(candidatedRechargeList, new Comparator<PaymentRechargeList>() {
            @Override
            public int compare(final PaymentRechargeList o1, final PaymentRechargeList o2) {
                int result = 0;
                /*if (!o1.getExpireDate().equals(o2.getExpireDate())) {
                    return o1.getExpireDate().before(o2.getExpireDate()) ? -1 : 1;
                }*/
                final CurrencyType o1Currency = o1.getVirtualCurrencyType();
                final CurrencyType o2Currency = o2.getVirtualCurrencyType();
                if (o1Currency.equals((Object)o2Currency)) {
                    if (CurrencyType.RECHARGE.equals((Object)o1Currency)) {
                        final Float o1Ratio = o1.getDisacountRatio();
                        final Float o2Ratio = o2.getDisacountRatio();
                        if (Float.isNaN(o1Ratio)) {
                            return 1;
                        }
                        if (Float.isNaN(o2Ratio)) {
                            return -1;
                        }
                        result = ((o1Ratio > o2Ratio) ? -1 : ((o1Ratio < o2Ratio) ? 1 : 0));
                    }
                }
                else {
                    result = (CurrencyType.FREE.equals((Object)o1Currency) ? -1 : 1);
                }
                return result;
            }
        });

        return candidatedRechargeList;
    }
}
